package list;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author
 * @Title: TestJoin
 * @Description:
 * @date 2022/8/25 2:14 下午
 */
public class TestJoin {

    /**
     * 拼接list
     */
    @Test
    public void test1(){
        List<String> list = Arrays.asList("a", "b", null, "d");

        String join = Joiner.on("@").skipNulls().join(list);
        System.out.println(join);


        String result2 = list.stream().collect(Collectors.joining("@"));
        System.out.println(result2);
    }

    @Test
    public void test2(){
        List<String> list = Arrays.asList("a", "b", null, "c");
        String s = Joiner.on("-").skipNulls().join(list);
        System.out.println(s);

        String collect = list.stream().collect(Collectors.joining("-"));
        System.out.println(collect);
    }

    @Test
    public void test3(){
        String s = "a,b,c";
        String result = Joiner.on("/").skipNulls().join(Splitter.on(",").split(s));
        System.out.println(result);
    }

}
